<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" :append-to-body="true" :close-on-click-modal="false" :before-close="handleBeforeClose">
    <div class="dialogbody">
      <div class="left_box">
        <div class="top_box">已选表({{ tableNumber }}个)</div>
        <div class="top_buttom">
          <span
            v-for="(v, i) in table_array"
            :key="i"
            @click="labelClick(v)"
            :style="{ 'background-color': v.label == labelTitle ? 'blue' : '', color: v.label == labelTitle ? 'white' : '', 'font-size': '10px' }"
            >{{ v.label }}</span
          >
        </div>
      </div>
      <div class="right_box">
        <el-form label-position="right" label-width="100px">
          <el-table :data="tableData" style="width: 100%" max-height="250">
            <el-table-column :label="title + '配置'" width="120" align="center">
              <el-table-column v-if="title == '增加字符'" prop="col" label="字段名" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="addCharacterDto[Number(scope.$index)].col" filterable placeholder="请选择处理的列名">
                    <el-option v-for="item in columnList" :key="item.value" :label="item.label" :value="item.label"> </el-option>
                  </el-select>
                </template> 
              </el-table-column>

              <el-table-column v-if="title == '增加字符'" prop="zip" label="配置" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="addCharacterDto[Number(scope.$index)].way" filterable placeholder="请选择配置">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '增加字符'" prop="zip" label="增加字符" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model="addCharacterDto[Number(scope.$index)].tgt" placeholder="请输入增加字符"></el-input>
                </template>
              </el-table-column>

              <el-table-column v-if="title == '增加时间戳'" prop="col" label="字段名" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model="addTimestampDto[Number(scope.$index)].col" placeholder="请填写字段名"> </el-input>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '增加时间戳'" prop="zip" label="时间戳格式" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="addTimestampDto[Number(scope.$index)].format" filterable placeholder="请填写时间戳格式">
                    <el-option v-for="item in timeTypeoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '增加时间戳'" prop="zip" label="规则" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="addTimestampDto[Number(scope.$index)].rulevalue" filterable placeholder="请填写规则" @change="handleRuleChange(Number(scope.$index))">
                    <el-option v-for="item in ruleoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '增加时间戳'" prop="zip" label="选择固定时间" align="center" width="120">
                <template slot-scope="scope">
                  <el-date-picker
                    type="datetime"
                    v-model="addTimestampDto[Number(scope.$index)].tgt"
                    placeholder="选择日期"
                    :format="'yyyy-MM-dd HH:mm:ss'"
                    :disabled="addTimestampDto[Number(scope.$index)].rulevalue == 'null'"
                  >
                  </el-date-picker>
                </template>
              </el-table-column>

              <el-table-column v-if="title == '增加常值'" prop="col" label="字段名" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model="addConstantDto[Number(scope.$index)].col" placeholder="请填写字段名"> </el-input>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '增加常值'" prop="zip" label="数据类型" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="addConstantDto[Number(scope.$index)].dataType" filterable placeholder="请填写数据类型">
                    <el-option v-for="item in dataTypeoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '增加常值'" prop="zip" label="值" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="addConstantDto[Number(scope.$index)].tgt" filterable placeholder="请填写值">
                    <el-option v-for="item in priceoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                    <el-row style="padding-left: 10px">
                      <el-col :span="15"> <el-input v-model.trim="value1"></el-input></el-col>
                      <el-col :span="7">
                        <p @click="valueCustomizeTo" style="text-align: center"><i class="el-icon-plus"></i> 自定义</p>
                      </el-col>
                    </el-row>
                  </el-select>
                </template>
              </el-table-column>

              <el-table-column v-if="title == '去除首尾空格'" prop="col" label="字段名" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="removeSpaceDto[Number(scope.$index)].col" filterable placeholder="请选择处理的列名">
                    <el-option v-for="item in columnList" :key="item.value" :label="item.label" :value="item.label"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '去除首尾空格'" prop="zip" label="去除配置" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="removeSpaceDto[Number(scope.$index)].way" filterable placeholder="请填写去除配置">
                    <el-option v-for="item in removeConfigoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                  </el-select>
                </template>
              </el-table-column>

              <el-table-column v-if="title == '字符串长度截取'" prop="col" label="字段名" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="subStringDto[Number(scope.$index)].col" filterable placeholder="请选择处理的列名">
                    <el-option v-for="item in columnList" :key="item.value" :label="item.label" :value="item.label"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '字符串长度截取'" prop="zip" label="截取方式" align="center" width="120">
                <template slot-scope="scope">
                  <el-select v-model="subStringDto[Number(scope.$index)].way" filterable placeholder="请选择截取方式">
                    <el-option v-for="item in InterceptionMethodoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '字符串长度截取'" prop="start" label="开始位置" align="center" width="120">
                <template slot-scope="scope">
                  <el-input v-model="subStringDto[Number(scope.$index)].star" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请填写开始位置"></el-input>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '字符串长度截取'" prop="end" label="结束位置" align="center" width="120">
                <template slot-scope="scope">
                  <el-input v-model="subStringDto[Number(scope.$index)].end" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请填写结束位置"></el-input>
                </template>
              </el-table-column>

              <el-table-column v-if="title == '剔除字符'" prop="col" label="字段名" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="eliminateCharacterDto[Number(scope.$index)].col" filterable placeholder="请选择处理的列名">
                    <el-option v-for="item in columnList" :key="item.value" :label="item.label" :value="item.label"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '剔除字符'" prop="zip" label="剔除字符" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model="eliminateCharacterDto[Number(scope.$index)].tgt" placeholder="请填写将要剔除的字符"></el-input>
                </template>
              </el-table-column>

              <el-table-column v-if="title == '空值转换'" prop="col" label="字段名" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="nullConversionDto[Number(scope.$index)].col" filterable placeholder="请选择处理的列名">
                    <el-option v-for="item in columnList" :key="item.value" :label="item.label" :value="item.label"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '空值转换'" prop="zip" label="替换为" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model="nullConversionDto[Number(scope.$index)].tgt" placeholder="请填写将要替换的值"></el-input>
                </template>
              </el-table-column>

              <el-table-column v-if="title == '字符串替换'" prop="col" label="字段名" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="characterReplaceDto[Number(scope.$index)].col" filterable placeholder="请选择处理的列名">
                    <el-option v-for="item in columnList" :key="item.value" :label="item.label" :value="item.label"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '字符串替换'" label="普换内容" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model="characterReplaceDto[Number(scope.$index)].now" placeholder="请填写要被替换的内容"></el-input>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '字符串替换'" label="位置限制" width="120" align="center">
                <template slot-scope="scope">
                  <el-select v-model="characterReplaceDto[Number(scope.$index)].way" filterable placeholder="请选择">
                    <el-option v-for="item in LocationRestrictions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column v-if="title == '字符串替换'" label="替换为" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model="characterReplaceDto[Number(scope.$index)].tgt" placeholder="请填写要被替换的内容"></el-input>
                </template>
              </el-table-column>

              <el-table-column fixed="right" label="操作" align="center" width="120">
                <template slot-scope="scope">
                  <el-button @click.native.prevent="deleteRow(Number(scope.$index), '+')" type="text" size="small">
                    <i style="font-size: 30px" class="el-icon-circle-plus-outline"></i>
                  </el-button>
                  <el-button @click.native.prevent="deleteRow(Number(scope.$index), '-')" type="text" size="small">
                    <i style="font-size: 30px" class="el-icon-remove-outline"></i>
                  </el-button>
                </template>
              </el-table-column>
            </el-table-column>
          </el-table>
        </el-form>
      </div>
    </div>
    <el-row type="flex" justify="center" align="right">
      <el-button type="primary" @click="btnClick" style="width: 15%; margin-top: 5%">提交</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import { getDataextractionJobDetail } from '@/api/dataextractionrealtime/single.js'
import { fetchcolumnList } from '@/api/metadata/column'
import dayjs from 'dayjs'
import { List } from 'echarts'
export default {
  props: ['model_title', 'table_array', 'readInfoid'],
  data() {
    return {
      title: this.model_title,
      dialogFormVisible: true,
      tableNumber: 1,
      labelTitle: '',
      CustomizeTovalue: '',
      columnList: [],
      value1: '',
      list: [],

      tableData: [{}],
      LocationRestrictions: [
        {
          value: 'all',
          label: '任意位置',
        },
        {
          value: 'star',
          label: '必须在开头',
        },
        {
          value: 'end',
          label: '必须在结尾',
        },
      ],
      removeConfigoptions: [
        {
          value: 'all',
          label: '去除首尾空格',
        },
        {
          value: 'star',
          label: '去除首部空格',
        },
        {
          value: 'end',
          label: '去除尾部空格',
        },
      ],
      dataTypeoptions: [
        {
          value: 'string',
          label: 'string',
        },
      ],

      InterceptionMethodoptions: [
        {
          value: 'pos',
          label: '正序',
        },
        {
          value: 'rev',
          label: '倒序',
        },
      ],
      options: [
        {
          value: 'star',
          label: ' 头部增加',
        },
        {
          value: 'end',
          label: '尾部增加',
        },
      ],
      priceoptions: [
        {
          value: '随机生成唯一值',
          label: '随机生成唯一值',
        },
      ],
      timeTypeoptions: [
        {
          value: '时间戳',
          label: '时间戳',
        },
        {
          value: 'yyyy-MM-dd',
          label: 'yyyy-MM-dd',
        },
        {
          value: 'yyyy/MM/dd',
          label: 'yyyy/MM/dd',
        },
        {
          value: 'yyyyMMdd',
          label: 'yyyyMMdd',
        },
        {
          value: 'yyyy_MM_dd',
          label: 'yyyy_MM_dd',
        },
      ],

      ruleoptions: [
        {
          value: 'null',
          label: '数据处理时间',
        },
        {
          value: 1,
          label: '固定时间',
        },
      ],
      addCharacterDto: [
        {
          col: '',
          way: '',
          tgt: '',
        },
      ],
      addTimestampDto: [
        {
          col: '',
          format: '',
          tgt: '',
          rulevalue: '',
        },
      ],

      addConstantDto: [
        {
          col: '',
          dataType: '',
          tgt: '',
        },
      ],
      removeSpaceDto: [
        {
          col: '',
          way: '',
        },
      ],
      subStringDto: [
        {
          col: '',
          way: '',
          star: '',
          end: '',
        },
      ],
      eliminateCharacterDto: [
        {
          col: '',
          tgt: '',
        },
      ],
      nullConversionDto: [
        {
          col: '',
          tgt: '',
        },
      ],
      characterReplaceDto: [
        {
          col: '',
          way: '',
          now: '',
          tgt: '',
        },
      ],
      labelId: '',
      addCharacterDtolist: [],
      addTimestampDtolist: [],
      addConstantDtolist: [],
      removeSpaceDtolist: [],
      subStringDtolist: [],
      eliminateCharacterDtolist: [],
      nullConversionDtolist: [],
      characterReplaceDtolist: [],
    }
  },
  watch: {
    addCharacterDto: {
      handler: function (newarr, oldarr) {
        console.log(newarr, '11111111111111111')
        if (this.model_title == '增加字符') {
          let list = JSON.parse(localStorage.getItem('addCharacterDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = newarr
            }
          })
          console.log(list, '1111111')
          localStorage.setItem('addCharacterDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
    addTimestampDto: {
      handler: function (newarr, oldarr) {
        if (this.model_title == '增加时间戳') {
          console.log(newarr, 'newarr')
          let list = JSON.parse(localStorage.getItem('addTimestampDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = newarr
            }
          })
          console.log(list, 'list')

          localStorage.setItem('addTimestampDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
    addConstantDto: {
      handler: function (newarr, oldarr) {
        if (this.model_title == '增加常值') {
          let list = JSON.parse(localStorage.getItem('addConstantDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = newarr
            }
          })
          localStorage.setItem('addConstantDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
    removeSpaceDto: {
      handler: function (newarr, oldarr) {
        if (this.model_title == '去除首尾空格') {
          let list = JSON.parse(localStorage.getItem('removeSpaceDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = newarr
            }
          })
          localStorage.setItem('removeSpaceDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
    subStringDto: {
      handler: function (newarr, oldarr) {
        console.log(newarr, '11111111111111111')
        if (this.model_title == '字符串长度截取') {
          let list = JSON.parse(localStorage.getItem('subStringDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = newarr
            }
          })
          localStorage.setItem('subStringDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
    eliminateCharacterDto: {
      handler: function (newarr, oldarr) {
        console.log(newarr, '11111111111111111')
        if (this.model_title == '剔除字符') {
          let list = JSON.parse(localStorage.getItem('eliminateCharacterDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = this.eliminateCharacterDto
            }
          })
          localStorage.setItem('eliminateCharacterDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
    nullConversionDto: {
      handler: function (newarr, oldarr) {
        if (this.model_title == '空值转换') {
          let list = JSON.parse(localStorage.getItem('nullConversionDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = newarr
            }
          })
          localStorage.setItem('nullConversionDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
    characterReplaceDto: {
      handler: function (newarr, oldarr) {
        if (this.model_title == '字符串替换') {
          let list = JSON.parse(localStorage.getItem('characterReplaceDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = newarr
            }
          })
          localStorage.setItem('characterReplaceDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
    eliminateCharacterDto: {
      handler: function (newarr, oldarr) {
        console.log(newarr, '11111111111111111')
        if (this.model_title == '剔除字符') {
          let list = JSON.parse(localStorage.getItem('eliminateCharacterDto'))
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              v.list = this.eliminateCharacterDto
            }
          })
          localStorage.setItem('eliminateCharacterDto', JSON.stringify(list))
        }
      },
      deep: true,
    },
  },
  mounted() {
    if (this.readInfoid.addroedit == 'update') {
      this.aaa()
    } else if (this.readInfoid.addroedit == 'create') {
      if (this.table_array.length) {
        this.labelClick(this.table_array[0])
      }
      this.tableData.push({})
      if (this.model_title == '增加字符') {
        if (!localStorage.getItem('addCharacterDto')) {
          this.table_array.map((v, i) => {
            this.addCharacterDtolist.push({
              name: v.label,
              id: v.id,
            })
          })
          localStorage.setItem('addCharacterDto', JSON.stringify(this.addCharacterDtolist))
        }
      } else if (this.model_title == '增加时间戳') {
        if (!localStorage.getItem('addTimestampDto')) {
          this.table_array.map((v, i) => {
            this.addTimestampDtolist.push({
              name: v.label,
              id: v.id,
            })
          })
          localStorage.setItem('addTimestampDto', JSON.stringify(this.addTimestampDtolist))
        }
      } else if (this.model_title == '增加常值') {
        if (!localStorage.getItem('addConstantDto')) {
          this.table_array.map((v, i) => {
            this.addConstantDtolist.push({
              name: v.label,
              id: v.id,
            })
          })
          localStorage.setItem('addConstantDto', JSON.stringify(this.addConstantDtolist))
        }
      } else if (this.model_title == '去除首尾空格') {
        if (!localStorage.getItem('removeSpaceDto')) {
          this.table_array.map((v, i) => {
            this.removeSpaceDtolist.push({
              name: v.label,
              id: v.id,
            })
          })
          localStorage.setItem('removeSpaceDto', JSON.stringify(this.removeSpaceDtolist))
        }
      } else if (this.model_title == '字符串长度截取') {
        if (!localStorage.getItem('subStringDto')) {
          this.table_array.map((v, i) => {
            this.subStringDtolist.push({
              name: v.label,
              id: v.id,
            })
          })
          localStorage.setItem('subStringDto', JSON.stringify(this.subStringDtolist))
        }
      } else if (this.model_title == '剔除字符') {
        if (!localStorage.getItem('eliminateCharacterDto')) {
          this.table_array.map((v, i) => {
            this.eliminateCharacterDtolist.push({
              name: v.label,
              id: v.id,
            })
          })
          localStorage.setItem('eliminateCharacterDto', JSON.stringify(this.eliminateCharacterDtolist))
        }
      } else if (this.model_title == '空值转换') {
        if (!localStorage.getItem('nullConversionDto')) {
          this.table_array.map((v, i) => {
            this.nullConversionDtolist.push({
              name: v.label,
              id: v.id,
            })
          })
          localStorage.setItem('nullConversionDto', JSON.stringify(this.nullConversionDtolist))
        }
      } else if (this.model_title == '字符串替换') {
        if (!localStorage.getItem('characterReplaceDto')) {
          this.table_array.map((v, i) => {
            this.characterReplaceDtolist.push({
              name: v.label,
              id: v.id,
            })
          })
          localStorage.setItem('characterReplaceDto', JSON.stringify(this.characterReplaceDtolist))
        }
      }
    }
  },
  methods: {
    aaa() {
      getDataextractionJobDetail(this.readInfoid.id).then((response) => {
        if (response.data.code === 0) {
          this.editdata = response.data.data
          console.log(this.editdata, '---> this.editdata ')
          let list = []
          let list0 = []
          let list1 = []
          let list2 = []
          let list3 = []
          let list4 = []
          let list5 = []
          let list6 = []
          let list7 = []
          this.editdata.dataExtractionDetailList.map((v, i) => {
            if (v.rep && v.rep.length > 0) {
              list0.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: v.rep,
              })
              localStorage.setItem('characterReplaceDto', JSON.stringify(list0))
            } else {
              list0.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: [],
              })
              this.tableData = [{}]
              localStorage.setItem('characterReplaceDto', JSON.stringify(list0))
            }

            if (v.nvl && v.nvl.length > 0) {
              list1.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: v.nvl,
              })

              localStorage.setItem('nullConversionDto', JSON.stringify(list1))
            } else {
              list1.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: [],
              })
              this.tableData = [{}]
              localStorage.setItem('nullConversionDto', JSON.stringify(list1))
            }

            if (v.del && v.del.length > 0) {
              list3.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: v.del,
              })

              localStorage.setItem('eliminateCharacterDto', JSON.stringify(list3))
            } else {
              list3.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: [],
              })
              this.tableData = [{}]
              localStorage.setItem('eliminateCharacterDto', JSON.stringify(list3))
            }

            if (v.sub && v.sub.length > 0) {
              list4.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: v.sub,
              })

              localStorage.setItem('subStringDto', JSON.stringify(list4))
            } else {
              list4.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: [],
              })
              this.tableData = [{}]
              localStorage.setItem('subStringDto', JSON.stringify(list4))
            }

            if (v.tri && v.tri.length > 0) {
              list5.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: v.tri,
              })

              localStorage.setItem('removeSpaceDto', JSON.stringify(list5))
            } else {
              list5.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: [],
              })
              this.tableData = [{}]
              localStorage.setItem('removeSpaceDto', JSON.stringify(list5))
            }
            if (v.addcol && v.addcol.length > 0) {
              list.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: v.addcol,
              })

              localStorage.setItem('addConstantDto', JSON.stringify(list))
            } else {
              list.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: [],
              })
              this.tableData = [{}]
              localStorage.setItem('addConstantDto', JSON.stringify(list))
            }
            if (v.addtime && v.addtime.length > 0) {
              list6.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: v.addtime,
              })

              localStorage.setItem('addTimestampDto', JSON.stringify(list6))
            } else {
              list6.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: [],
              })
              this.tableData = [{}]
              localStorage.setItem('addTimestampDto', JSON.stringify(list6))
            }
            if (v.addstr && v.addstr.length > 0) {
              list7.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: v.addstr,
              })
              console.log(list7, '--->list7')

              localStorage.setItem('addCharacterDto', JSON.stringify(list7))
            } else {
              list7.push({
                id: v.sourceTableId,
                name: v.sourceTableName,
                list: [],
              })
              console.log(list7, '--->list7')
              this.tableData = [{}]
              localStorage.setItem('addCharacterDto', JSON.stringify(list7))
            }
          })
        }
      })
    },
    handleRuleChange(index) {
      if (this.addTimestampDto[index].rulevalue === 'null') {
        this.addTimestampDto[index].tgt = null // 清空固定时间数据
      }
    },
    ziduancheckout(id) {
      fetchcolumnList({ sourceId: id }).then((res) => {
        if (res.data.code === 0) {
          this.columnList = []
          for (let i = 0; i < res.data.data.length; i++) {
            var cobj = {
              value: res.data.data[i].id,
              label: res.data.data[i].columnName,
            }
            this.columnList.push(cobj)
          }
        } else {
          console.log('未获取到')
        }
      })
    },

    CustomizeTo() {
      this.timeTypeoptions.push({
        value: this.CustomizeTovalue,
        label: this.CustomizeTovalue,
      })
    },
    valueCustomizeTo() {
      if (this.value1 !== '') {
        this.priceoptions.push({
          value: this.value1,
          label: this.value1,
        })
      }
    },
    labelClick(done) {
      this.labelTitle = done.label
      this.labelId = done.id

      if (this.model_title == '增加字符') {
        if (localStorage.getItem('addCharacterDto')) {
          let list = JSON.parse(localStorage.getItem('addCharacterDto'))

          list.map((v) => {
            if (this.labelTitle == v.name) {
              this.tableData = []
              if (v.list) {
                v.list.map((v1) => {
                  this.tableData.push({})
                })
                this.addCharacterDto = v.list
              } else {
                this.tableData = [{}]
                this.addCharacterDto = [{}]
              }
            }
          })
        }
      } else if (this.model_title == '增加时间戳') {
        if (localStorage.getItem('addTimestampDto')) {
          let list = JSON.parse(localStorage.getItem('addTimestampDto'))
          this.tableData = []
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              this.tableData = []
              this.addTimestampDto = []
              if (v.list) {
                v.list.map((v1, i1) => {
                  this.tableData.push({})
                })
                this.addTimestampDto = v.list
              } else {
                this.tableData = [{}]
                this.addTimestampDto = [{}]
              }
            }
          })
        }
      } else if (this.model_title == '增加常值') {
        if (localStorage.getItem('addConstantDto')) {
          let list = JSON.parse(localStorage.getItem('addConstantDto'))
          this.tableData = []
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              this.tableData = []
              this.addConstantDto = []
              if (v.list) {
                v.list.map((v1, i1) => {
                  this.tableData.push({})
                })
                this.addConstantDto = v.list
              }else {
                this.tableData = [{}]
                this.addConstantDto = [{}]
              }
            }
          })
        }
      } else if (this.model_title == '去除首尾空格') {
        if (localStorage.getItem('removeSpaceDto')) {
          let list = JSON.parse(localStorage.getItem('removeSpaceDto'))
          this.tableData = []
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              this.removeSpaceDto = []
              this.tableData = []
              if (v.list) {
                v.list.map((v1, i1) => {
                  this.tableData.push({})
                })
                this.removeSpaceDto = v.list
              }else {
                this.tableData = [{}]
                this.removeSpaceDto = [{}]
              }
            }
          })
        }
      } else if (this.model_title == '字符串长度截取') {
        if (localStorage.getItem('subStringDto')) {
          let list = JSON.parse(localStorage.getItem('subStringDto'))
          this.tableData = []
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              this.subStringDto = []
              this.tableData = []
              if (v.list) {
                v.list.map((v1, i1) => {
                  this.tableData.push({})
                })
                this.subStringDto = v.list
              }else {
                this.tableData = [{}]
                this.subStringDto = [{}]
              }
            }
          })
        }
      } else if (this.model_title == '剔除字符') {
        if (localStorage.getItem('eliminateCharacterDto')) {
          let list = JSON.parse(localStorage.getItem('eliminateCharacterDto'))
          this.tableData = []
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              this.eliminateCharacterDto = []
              this.tableData = []
              if (v.list) {
                v.list.map((v1, i1) => {
                  this.tableData.push({})
                })
                this.eliminateCharacterDto = v.list
              }else {
                this.tableData = [{}]
                this.eliminateCharacterDto = [{}]
              }
            }
          })
        }
      } else if (this.model_title == '空值转换') {
        if (localStorage.getItem('nullConversionDto')) {
          let list = JSON.parse(localStorage.getItem('nullConversionDto'))
          this.tableData = []
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              this.nullConversionDto = []
              this.tableData = []
              if (v.list) {
                v.list.map((v1, i1) => {
                  this.tableData.push({})
                })
                this.nullConversionDto = v.list
              }else {
                this.tableData = [{}]
                this.nullConversionDto = [{}]
              }
            }
          })
        }
      } else if (this.model_title == '字符串替换') {
        if (localStorage.getItem('characterReplaceDto')) {
          let list = JSON.parse(localStorage.getItem('characterReplaceDto'))
          this.tableData = []
          list.map((v, i) => {
            if (this.labelTitle == v.name) {
              this.characterReplaceDto = []
              this.tableData = []
              if (v.list.length > 0) {
                v.list.map((v1, i1) => {
                  this.tableData.push({})
                })
                this.characterReplaceDto = v.list
              }else {
                this.tableData = [{}]
                this.characterReplaceDto = [{}]
              }
            }
          })
        }
      }
      this.ziduancheckout(done.id)
    },
    handleBeforeClose(done) {
      this.dialogFormVisible = false
      this.$emit('change')
    },
    deleteRow(item, type) {
      if (type == '+') {
        this.tableData.push({})
        if (this.model_title == '增加字符') {
          if (localStorage.getItem('addCharacterDto')) {
            let list = JSON.parse(localStorage.getItem('addCharacterDto'))
            list.map((v, i) => {
              if (v.id == this.labelId) {
                v.list.push({
                  col: '',
                  way: '',
                  tgt: '',
                })
                this.addCharacterDto = v.list
              }
            })
            localStorage.setItem('addCharacterDto', JSON.stringify(list))
          }
        } else if (this.model_title == '增加时间戳') {
          if (localStorage.getItem('addTimestampDto')) {
            let list = JSON.parse(localStorage.getItem('addTimestampDto'))
            list.map((v, i) => {
              if (v.id == this.labelId) {
                v.list.push({
                  col: '',
                  format: '',
                  tgt: '',
                  rulevalue: '',
                })
                this.addTimestampDto = v.list
              }
            })
            localStorage.setItem('addTimestampDto', JSON.stringify(list))
          }
        } else if (this.model_title == '增加常值') {
          if (localStorage.getItem('addConstantDto')) {
            let list = JSON.parse(localStorage.getItem('addConstantDto'))
            list.map((v, i) => {
              if (v.id == this.labelId) {
                v.list.push({
                  col: '',
                  dataType: '',
                  tgt: '',
                })
                this.addConstantDto = v.list
              }
            })
            localStorage.setItem('addConstantDto', JSON.stringify(list))
          }
        } else if (this.model_title == '去除首尾空格') {
          if (localStorage.getItem('removeSpaceDto')) {
            let list = JSON.parse(localStorage.getItem('removeSpaceDto'))
            list.map((v, i) => {
              if (v.id == this.labelId) {
                v.list.push({
                  col: '',
                  way: '',
                })
                this.removeSpaceDto = v.list
              }
            })
            localStorage.setItem('removeSpaceDto', JSON.stringify(list))
          }
        } else if (this.model_title == '字符串长度截取') {
          if (localStorage.getItem('subStringDto')) {
            let list = JSON.parse(localStorage.getItem('subStringDto'))
            list.map((v, i) => {
              if (v.id == this.labelId) {
                v.list.push({
                  col: '',
                  way: '',
                  star: '',
                  end: '',
                })
                this.subStringDto = v.list
              }
            })
            localStorage.setItem('subStringDto', JSON.stringify(list))
          }
        } else if (this.model_title == '剔除字符') {
          if (localStorage.getItem('eliminateCharacterDto')) {
            let list = JSON.parse(localStorage.getItem('eliminateCharacterDto'))
            list.map((v, i) => {
              if (v.id == this.labelId) {
                v.list.push({
                  col: '',
                  tgt: '',
                })
                this.eliminateCharacterDto = v.list
              }
            })
            localStorage.setItem('eliminateCharacterDto', JSON.stringify(list))
          }
        } else if (this.model_title == '空值转换') {
          if (localStorage.getItem('nullConversionDto')) {
            let list = JSON.parse(localStorage.getItem('nullConversionDto'))
            list.map((v, i) => {
              if (v.id == this.labelId) {
                v.list.push({
                  col: '',
                  tgt: '',
                })
                this.nullConversionDto = v.list
              }
            })
            localStorage.setItem('nullConversionDto', JSON.stringify(list))
          }
        } else if (this.model_title == '字符串替换') {
          if (localStorage.getItem('characterReplaceDto')) {
            let list = JSON.parse(localStorage.getItem('characterReplaceDto'))
            list.map((v, i) => {
              if (v.id == this.labelId) {
                v.list.push({
                  col: '',
                  way: '',
                  now: '',
                  tgt: '',
                })
                this.characterReplaceDto = v.list
              }
            })
            localStorage.setItem('characterReplaceDto', JSON.stringify(list))
          }
        }
      } else if (type == '-') {
        this.tableData.splice(item, 1)
        if (this.model_title == '增加字符') {
          this.addCharacterDto.splice(item, 1)
        } else if (this.model_title == '增加时间戳') {
          this.addTimestampDto.splice(item, 1)
        } else if (this.model_title == '增加常值') {
          this.addConstantDto.splice(item, 1)
        } else if (this.model_title == '去除首尾空格') {
          this.removeSpaceDto.splice(item, 1)
        } else if (this.model_title == '字符串长度截取') {
          this.subStringDto.splice(item, 1)
        } else if (this.model_title == '剔除字符') {
          this.eliminateCharacterDto.splice(item, 1)
        } else if (this.model_title == '空值转换') {
          this.nullConversionDto.splice(item, 1)
        } else if (this.model_title == '字符串替换') {
          this.characterReplaceDto.splice(item, 1)
        }
      }
    },

    btnClick() {
      Date.prototype.format = function (format) {
        const padZero = (num) => (num < 10 ? '0' + num : num)
        const yyyy = this.getFullYear()
        const MM = padZero(this.getMonth() + 1)
        const dd = padZero(this.getDate())
        const HH = padZero(this.getHours())
        const mm = padZero(this.getMinutes())
        const ss = padZero(this.getSeconds())

        return format.replace('yyyy', yyyy).replace('MM', MM).replace('dd', dd).replace('HH', HH).replace('mm', mm).replace('ss', ss)
      }
      if (this.model_title == '增加时间戳') {
        let list = JSON.parse(localStorage.getItem('addTimestampDto'))
        list.map((item, index) => {
          if (item.list) {
            item.list.map((v, i) => {
              if (v.format == 'yyyy-MM-dd HH:mm:ss') {
                if (v.rulevalue !== 'null') {
                  v.tgt = new Date(v.tgt).format('yyyy-MM-dd HH:mm:ss')
                } else {
                  console.log(v.format)
                  v.tgt = 'null'
                }
              } else if (v.format == 'yyyy-MM-dd') {
                if (v.rulevalue !== 'null') {
                  v.tgt = new Date(v.tgt).format('yyyy-MM-dd HH:mm:ss')
                  console.log(v.tgt)
                } else {
                  console.log(v.format)
                  v.tgt = 'null'
                }
              } else if (v.format == 'yyyy/MM/dd') {
                if (v.rulevalue !== 'null') {
                  v.tgt = new Date(v.tgt).format('yyyy-MM-dd HH:mm:ss')
                  console.log(v.tgt)
                } else {
                  console.log(v.format)
                  v.tgt = 'null'
                }
              } else if (v.format == 'yyyyMMdd') {
                if (v.rulevalue !== 'null') {
                  v.tgt = new Date(v.tgt).format('yyyy-MM-dd HH:mm:ss')
                  console.log(v.tgt)
                } else {
                  console.log(v.format)
                  v.tgt = 'null'
                }
              } else if (v.format == 'yyyy_MM_dd') {
                if (v.rulevalue !== 'null') {
                  v.tgt = new Date(v.tgt).format('yyyy-MM-dd HH:mm:ss')
                  console.log(v.tgt)
                } else {
                  console.log(v.format)
                  v.tgt = 'null'
                }
              }
            })
          }
        })
        console.log(list)
        localStorage.setItem('addTimestampDto', JSON.stringify(list))
      }
      this.$emit('change')
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep(::-webkit-scrollbar) {
  display: block !important;
}
.left_box {
  width: 15%;
  height: 200px;
  margin: 20px 10px 20px 20px;
  background-color: white;
  border: 1px solid #b5b7ba;
  overflow-y: auto;
}

.top_box {
  width: 100%;
  height: 40px;
  text-align: center;
  line-height: 40px;
  background-color: #f5f7fa;
}
.top_buttom {
  height: 156px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
}
.top_buttom span {
  box-sizing: content-box;

  display: block;
  width: 90%;
  font-size: 20px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  color: white;
  border: 1px solid black;

  color: black;
}

.right_box {
  width: 90%;
  margin: 20px 20px 20px 10px;
}

.dialogbody {
  display: flex;
  background-color: #f5f7fa;
}
</style>
_oldarr_i_oldarr_i_oldarr_i_oldarr_i_oldarr_i_oldarr_i_oldarr_i_oldarr_i_oldarr_i_i_i_i_i_i_i_i_i_i_i_i_v1_i1_i_v1_i1_i_v1_i1_i_v1_i1_i_v1_i1_i_v1_i1_i_v1_i1_done_i_i_i_i_i_i_i_i_index_i_$event_$event_$event_$event
